package com.wanmait.CarTrading.DAO.impl;

import com.wanmait.CarTrading.DAO.CarBrandDAO;
import com.wanmait.CarTrading.Util.DBHelper;
import com.wanmait.CarTrading.Util.Pager;
import com.wanmait.CarTrading.vo.Brand;
import com.wanmait.CarTrading.vo.Car;
import com.wanmait.CarTrading.vo.Cartype;
import org.springframework.stereotype.Repository;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
@Repository
public class CarBrandDAOImpl implements CarBrandDAO {
    @Override
    public List<Brand> findAll() {
        return null;
    }

    @Override
    public Brand findById(Integer id) {
        return null;
    }

    @Override
    public List<Brand> findAll(Pager pager) {
        String sql=" select * from brand ";

        Connection conn=null;
        PreparedStatement ps=null;
        ResultSet rs=null;
        Brand brand=null;
       List <Brand> brands=new ArrayList<>();

        try {
            conn= DBHelper.getDBhelper().getConn();
            ps=conn.prepareStatement(sql);
            rs=ps.executeQuery();
            while (rs.next()){
                brand=new Brand();
                brand.setId(rs.getInt("id"));
                brand.setName(rs.getString("name"));
                System.out.println(brand.getName());
                brands.add(brand);

            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            DBHelper.getDBhelper().close(rs,ps,conn);
        }
        return brands;
    }

    @Override
    public int getDataCount() {
        return 0;
    }

    @Override
    public void insert(Brand object) {

    }

    @Override
    public void update(Brand object) {

    }

    @Override
    public void delete(Integer id) {

    }

    @Override
    public void delete(String ids) {

    }
}
